﻿
namespace CrudCategories.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data.Linq;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using Microsoft.ServiceModel.DomainServices.LinqToSql;


    // Implements application logic using the NorthWindDataContext context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class DomainServiceCategory : LinqToSqlDomainService<NorthWindDataContext>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        public IQueryable<Category> GetCategories()
        {
            return this.DataContext.Categories;
        }

        public void InsertCategory(Category category)
        {
            this.DataContext.Categories.InsertOnSubmit(category);
        }

        public void UpdateCategory(Category currentCategory)
        {
            this.DataContext.Categories.Attach(currentCategory, this.ChangeSet.GetOriginal(currentCategory));
        }

        public void DeleteCategory(Category category)
        {
            this.DataContext.Categories.Attach(category);
            this.DataContext.Categories.DeleteOnSubmit(category);
        }
    }
}


